/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sasp_messages;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author mauriello
 */
public class REQMasterCommand extends SASPCommand {
    private String clientAlias;
    private String ipAddress;

    public REQMasterCommand( ) {
        super( );
        this.setType(REQ_SN);
    }

    @Override
    public void updateCommandBody( ) {
        try {
            JSONObject commandBody = new JSONObject();
            commandBody.put("IPAddress", ipAddress);
            commandBody.put("ClientAlias", clientAlias);
            this.setCommandBody(commandBody);
        } catch (JSONException ex) {
            Logger.getLogger(REQMasterCommand.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public REQMasterCommand( int _o, int _d, int _m, String _i, String _a ) {
        super( _o, _d, _m );
        this.setType(REQ_SN);
        ipAddress = _i;
        clientAlias = _a;
        saspmanager.SASPManagerApp.addLine("RMC - Request Super Node Command Generated");
        try {
            JSONObject commandBody = new JSONObject();
            commandBody.put("IPAddress", ipAddress);
            commandBody.put("ClientAlias", clientAlias);
            this.setCommandBody(commandBody);
        } catch (JSONException ex) {
            Logger.getLogger(REQMasterCommand.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public REQMasterCommand( String _s ) {
        super( _s );
        try {
            saspmanager.SASPManagerApp.addLine("RMC - Request Super Node Received");
            ipAddress = this.getCommandBody().getString("IPAddress");
            clientAlias = this.getCommandBody().getString("ClientAlias");
        } catch (JSONException ex) {
            Logger.getLogger(REQMasterCommand.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public String getClientAlias() {
        return clientAlias;
    }

    public void setClientAlias(String clientAlias) {
        this.clientAlias = clientAlias;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    @Override
    public SASPReply execute() {
        saspmanager.SASPManagerApp.addLine("RMC - ACK Reply Generated");
        return null; //new ACKReply(this.getDestinationID(),this.getOriginatorID(),this.getMessageID());
    }
}
